﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using QuocTeViet.DO;
using QuocTeViet.BL;

namespace QuocTeViet.AdminCP.PageUC
{
    public partial class ucCartUser : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if(!IsPostBack)
                loaddata();
        }

        public void loaddata()
        {
            DataTable dt = new cmsDonHangBL().SelectUser(-1);
            if (dt.Rows.Count > 0)
            {
                {
                    GrDonhang.DataSource = dt;
                    GrDonhang.DataBind();
                }
            }
            else
            {
                GrDonhang.Attributes.Add("EmplyTextData", "Không có đơn hàng!!");
            }
        }

        protected void XuLy_LinkButton_Click(object sender, CommandEventArgs e)
        {
            int id = int.Parse(e.CommandArgument.ToString());
            cmsDonHangDO obj = new cmsDonHangDO();
            obj = new cmsDonHangBL().Select(new cmsDonHangDO { DonHangID = id });
            bool xuLy = !bool.Parse(obj.XuLy.ToString());

            new cmsDonHangBL().Update(obj);
            
            //obj.XuLy = !bol;
            //new cmsDonHangBL().Update(obj);
            loaddata();
        }
        protected void imgbtnDelete_Click(object sender, CommandEventArgs e)
        {
            int id = int.Parse(e.CommandArgument.ToString());
            new cmsDonHangBL().Delete(new cmsDonHangDO { DonHangID = id });
            Functions.Alert("Xóa bản ghi thành công!", Request.Url.ToString());
        }


        protected void GrDonhang_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {

        }

        protected void GrDonhang_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GrDonhang.PageIndex = e.NewPageIndex;
            loaddata();
        }
    }
}